package org.westos.ChinaSoft3;

import java.io.*;
import java.util.ArrayList;
import java.util.Scanner;

public class Delete {
    public static void main(String[] args) throws IOException {
        OutputStreamWriter out = null;
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入要删除员工的编号：");
        int i = sc.nextInt();

        try {
            //读取文件
            ReadFile readFile = new ReadFile();
            ArrayList<Employee> list = readFile.readFile();
            //删除对应的数据
            Employee remove = list.remove(i - 1);
            System.out.println("删除成功，删除对象信息为：" + remove);
            //将删除后的数据集重新写入原文件
            File file = new File("1.txt");

            out = new OutputStreamWriter(new FileOutputStream(file));
            String str = null;
            for (Employee emp1 : list) {
                str = emp1.getId() + "," + emp1.getName() + "," + emp1.getAge() + "," + emp1.getSex() + "," + emp1.getSA();
                out.write(str);
                out.write("\n");
            }

        } catch (IOException e) {
            System.out.println("该用户不存在，请输入准确的编号。");
            System.out.println("删除失败");
        }finally {
            out.close();
        }
    }
}
